package com.example.smartcamera.slice;

import com.example.smartcamera.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ListContainer;
import ohos.agp.components.TabList;
import ohos.agp.components.Image;

import java.util.ArrayList;

public class MineAbilitySlice extends AbilitySlice {
    private static final int TAB_WIDTH = 64;
    private static final int TAB_PADDING_LEFT = 12;
    private static final int TAB_PADDING_RIGHT = 12;
    private static final int TAB_PADDING_BOTTOM = 12;
    private static final int TAB_PADDING_TOP = 12;
    private TabList tabList3;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_mine);
        //初始化布局，各种按钮
        initComponents();
        addTabSelectedListener();
        /**initListContainer();*/
        Image image = (Image) findComponentById(ResourceTable.Id_i_animator);
        image.setCornerRadius(1000f);
    }

    //初始化导航栏
    private void initTab() {
        if (tabList3.getTabCount() == 0) {
            tabList3.addTab(createTab("实时"));
            tabList3.addTab(createTab("相册"));
            tabList3.addTab(createTab("回放"));
            tabList3.addTab(createTab("我的"));
            tabList3.setFixedMode(true);
            tabList3.getTabAt(3).select();
            tabList3.getTabAt(0).setClickedListener(lisener->present(new RealTimeAbilitySlice() , new Intent()));
            tabList3.getTabAt(1).setClickedListener(lisener->present(new PhotoAbilitySlice() , new Intent()));
            tabList3.getTabAt(2).setClickedListener(lisener->present(new PlayBackAbilitySlice() , new Intent()));
            tabList3.getTabAt(3).setClickedListener(lisener->present(new MineAbilitySlice() , new Intent()));
        }
    }

    //添加点击功能（在这里做ability跳转）
    private void addTabSelectedListener() {
        tabList3.addTabSelectedListener(new TabList.TabSelectedListener() {
            @Override
            public void onSelected(TabList.Tab tab) {
            }

            @Override
            public void onUnselected(TabList.Tab tab) {
            }

            @Override
            public void onReselected(TabList.Tab tab) {
            }
        });
    }

    //创建下方导航栏
    private TabList.Tab createTab(String text) {
        TabList.Tab tab = tabList3.new Tab(this);
        tab.setText(text);
        tab.setMinWidth(TAB_WIDTH);
        tab.setPadding(TAB_PADDING_LEFT, TAB_PADDING_TOP, TAB_PADDING_RIGHT, TAB_PADDING_BOTTOM);
        return tab;
    }

    private void initComponents() {
        tabList3 = (TabList) findComponentById(ResourceTable.Id_tab_list_mine);
        initTab();

    }


   /** private void initListContainer(){
        // 1.获取xml布局中的ListContainer组件
        ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_list_container1);
        // 2.实例化数据源
        List<ItemDemo> list = getData();
        // 3.初始化Provider对象
        ItemProvider itemProvider = new ItemProvider(list, this);
        // 4.适配要展示的内容数据
        listContainer.setItemProvider(itemProvider);

    }*/
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
